# a script that reads the OECD ICIO 2018 CSV files
# version: Oct 2019
# ENSURE that the script is in the path: addpath ("/[insert the path to your Octave folder]/Octave")

# before running this script, download the OECD ICIO 2018 CSV files from http://www.oecd.org/sti/ind/inter-country-input-output-tables.htm

# enter year
year = input ("enter year: ")
y = num2str (year);
# identify the CSV file with the downloaded ICIO table for year y
filename = ["/[insert the path to the CSV input file]/ICIO2018_" y ".CSV"];
# the 2018 release of the OECD ICIO tables covers 64 countries, the rest of the world and split tables for China and Mexico, with a total of 69 country categories
# it covers 36 industries based on ISIC rev.4, leading to a total of 69 x 36 = 2484 country-industry categories
# 1. read the matix of intermediate demand Z0, 2484 x 2484
Z0 = dlmread (filename, ",", [1, 1, 2484, 2484]);
# 2. read the matrix of final demand F0, 2484 x 390 (390 = 65 countries x 6 demand categories)
F0 = dlmread (filename, ",", [1, 2485, 2484, 2874]);
# 3.1. read the matrix of taxes less subsidies on imtermediate products TLSi0, 65 x 2484
TLSi0 = dlmread (filename, ",", [2485, 1, 2549, 2484]);
# 3.2. read the matrix of taxes less subsidies on final products TLSf0, 65 x 390
TLSf0 = dlmread (filename, ",", [2485, 2485, 2549, 2874]);
# 4. read the row vector of value added v0, 1 x 2484
v0 = dlmread (filename, ",", [2550, 1, 2550, 2484]);
# 5. read the row vector of x0 total output, 1 x 2484
x0 = dlmread (filename, ",", [2551, 1, 2551, 2484]);
# save file
filename = ["/[insert the path to the output data file]/ICIO2018_" y "_octave"];
save (filename, "Z0", "F0", "TLSi0", "TLSf0", "v0", "x0")
# clear all
clear
# END of script
